package com.company;

public class TestThread {
    private static void testCountThread(Counter counter){
        Thread t_add = new Thread(()->{
            for (int i = 0;i<10000;i++){
                counter.add();
            }
        });

        Thread t_dec = new Thread(()->{
            for (int i = 0;i<10000;i++){
                counter.dec();
            }
        });

        t_add.start();
        t_dec.start();
        try {
            t_add.join();
            t_dec.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println(counter.get());
    }

    public static void testBadCounter(){
        testCountThread(new BadCounter());
    }

    public static void testAppleCounter(){
        testCountThread(new AppleCounter());
    }

    public static void testMongoCounter(){
        testCountThread(new MongoCounter());
    }

    public static void testBananaCounter(){testCountThread(new BananaCounter());}
}
